package cn.gglol.code.generator.mapper;


import cn.gglol.code.generator.domain.JvvTableColumn;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface JvvTableColumnMapper
{
    /**
     * 根据表名称查询列信息
     * 
     * @param tableName 表名称
     * @return 列信息
     */
    @Select("select column_name columnName, " +
            "(case when (is_nullable = 'no' && column_key != 'PRI') then '1' else null end) isRequired, " +
            "(case when column_key = 'PRI' then '1' else '0' end) isPk, " +
            "ordinal_position as sort, " +
            "column_comment columnComment, " +
            "(case when extra = 'auto_increment' then '1' else '0' end) isIncrement, " +
            "column_type columnType " +
            "from information_schema.columns " +
            "where lower(table_schema) = (select database()) and table_name = #{tableName} " +
            "order by ordinal_position")
    List<JvvTableColumn> selectDbTableColumnsByName(String tableName);

}